﻿//-- =============================================
//-- Author:	    Saghari, Farid
//-- Create date:   1389/12/20
//-- Description:	Business Logic Layer Base Class
//-- E-Mail:    	fredmcs@live.com
//-- Mobile:        0937-241-3499
//-- Last Update:   1390/01/10 13:01
//-- =============================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChequeManagement.BLL
{
    /// <summary>
    /// This Class contains number of Field,properties,method, constructor
    /// </summary>
    public abstract class BaseFactory
    {
        private string tableName;
        private ChequeManagement.DAL.BaseDAL dataObject;

        /// <summary>
        /// This constructor call ApplicationInfo class on Common layer
        /// </summary>
        /// <param name="tableName" Type="string"></param>
        /// <ApplicationInfo>this class has a constructor that give a parameter that this parameter is tablename</ApplicationInfo>
        public BaseFactory(string tableName)
        {
            this.tableName = tableName;
            Common.ApplicationInfo appInfo = new Common.ApplicationInfo(tableName);

            //Recomende:----------------------------------------------------

            //try
            //{
            //    dataObject = (ChequeManagement.DAL.BaseDAL)Activator.CreateInstance(Type.GetType(appInfo.DataAccessLayer));
            //}
            //catch (TypeLoadException e)
            //{
            //    //Write an appropriate message
            //    Console.WriteLine(e.Message);
            //}
            //catch (Exception e)
            //{
            //    ////Write an appropriate message
            //    Console.WriteLine(e.Message);
            //}

            //------------------------------------------------------------------

            dataObject = (ChequeManagement.DAL.BaseDAL)Activator.CreateInstance(Type.GetType(appInfo.DataAccessLayer));
        }

        /// <summary>
        /// This property include "get" for return value this property is read only
        /// </summary> 
        public object DataAccessLayer
        {
            get
            {
                return (dataObject);
            }
        }

        /// <summary>
        /// this method is for open connection and connect to dataBase 
        /// </summary>
        /// <return>this type is void and Do not return</return>
        public void BeginTransaction()
        {
            try
            {
                this.dataObject.BeginTransaction();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// this method is for do your command on dataBase 
        /// </summary>
        /// <return>this type is void and Do not return</return>
        public void CommitTransaction()
        {
            try
            {
                this.dataObject.CommitTransaction();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        /// <summary>
        /// this method is for undo your command from dataBase
        /// </summary>
        /// <return>this type is void and Do not return</return>
        public void RollBackTransaction()
        {
            try
            {
                this.dataObject.RollBackTransaction();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}